﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Autodesk.AutoCAD.Geometry;

namespace _02AddEntityTools
{
    public static partial class GeoBaseTools
    {
        /// <summary>
        /// 角度转换为弧度的函数
        /// </summary>
        /// <param name="degree">角度值</param>
        /// <returns>弧度值</returns>
        public static double degreeToAngle(this double degree)
        {
            return degree * Math.PI / 180;
        }
        /// <summary>
        /// 弧度转换为角度的函数
        /// </summary>
        /// <param name="angle">弧度值</param>
        /// <returns>角度值</returns>
        public static double angleTodegree(this double angle)
        {
            return angle * 180 / Math.PI;
        }
        /// <summary>
        /// 判断三个三维点的xy平面投影点是否共线
        /// </summary>
        /// <param name="p1"> 起始点(第一个点)</param>
        /// <param name="p2"> 中间点(第二个点)</param>
        /// <param name="p3"> 结束点(第三个点)</param>
        /// <returns></returns>
        public static bool isOnOneLine(this Point3d p1,
            Point3d p2,
            Point3d p3)
        {
            Vector3d v21 = p2.GetVectorTo(p1);
            Vector3d v23 = p2.GetVectorTo(p3);
            if (v21.GetAngleTo(v23) == 0 || v21.GetAngleTo(v23) == Math.PI)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 计算三维点的xy平面投影点组成的向量与x轴的夹角
        /// </summary>
        /// <param name="startPoint">向量的起始点</param>
        /// <param name="endPoint">向量的终点</param>
        /// <returns>两个向量的夹角</returns>
        public static double getAngleWithXAsix(this Point3d startPoint, Point3d endPoint)
        {
            // 声明一个与X轴平行的向量
            Vector3d temp = new Vector3d(1, 0, 0);
            // 获取起点到终点的向量
            Vector3d vecStarToEnd = startPoint.GetVectorTo(endPoint);
            // 计算角度向量
            return vecStarToEnd.Y > 0 ? temp.GetAngleTo(vecStarToEnd) : -temp.GetAngleTo(vecStarToEnd);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="point1"></param>
        /// <param name="point2"></param>
        /// <returns></returns>
        public static double getDistanceBetweenTwoPoint(this Point3d point1, Point3d point2)
        {
            double lengh2 = (point1.X - point2.X) * (point1.X - point2.X) +
                (point1.Y - point2.Y) * (point1.Y - point2.Y) +
                (point1.Z - point2.Z) * (point1.Z - point2.Z);
            double lengh = Math.Sqrt(lengh2);
            return lengh;
        }

    }
}
